
import  {getMenu} from  '@/api/menu'
let menus = []
 await   getMenu().then(res=>{
  console.log(res,'===菜单')
  //路由拼接
  routesData(res.data.result)
  console.log('完成拼接之后的menus:', menus)
}).catch(error=>{
  console.log("加载数据失败。。。",error);
})
function routesData(result) {
  menus = result.map((item, index) => {
      //父路由
      let menu ={
        path:item.menuUrl,
        name:item.name,
        meta:{title:item.menuName,icon:item.iconName,top:true}
      }
      //子路由
      if(item.subMenus&&item.subMenus.length){
        menu.children = item.subMenus.map(child=>({
            path: child.menuUrl,
            name: child.name,
            meta: { title: child.menuName, icon: child.iconName },
             component: () =>import(`../views/${item.name}/${child.component}.vue`)  
        }))
      } else {
      menu.component = () => import(`../views/${item.name}/${item.component}.vue`)
    }
    return menu
  })
  //添加个人信息
  menus.push({
                            path: "modifyPwd",
                            name: "ModifyPwd",
                            meta: {
                                title: "修改密码",
                                icon: "PieChart"
                            },
                            component: () => import('@/views/profile/ModifyPwd.vue')
                        }),
                       menus.push( {
                            path: "info",
                            name: "Info",
                            meta: {
                                title: "个人信息",
                                icon: "Histogram"
                            },
                            component: () => import('@/views/profile/Info.vue')
                        })
  return menus

}
export default menus